var logData = [];
var logLen=0;
var appRouter = null;
const manba = require("manba");
module.exports = log= {
    log(opctions,router) {
        appRouter=router;
        return async (ctx, next) => {
            await new Promise((resolve, reject) => {
                if (ctx.request.url == "/logs") {
                    // if(logData.length==logLen){
                    //     ctx.body = {logs:logData[logData.length-1]||"",show:false};
                    // }else{
                    //     let logs=logData.slice(logLen)
                    //     ctx.body = {logs:logs||"",show:true};
                    //     // logLen=logData.length;
                    // }
                    // logLen=logData.length;
                    ctx.body = {logs:logData||"",show:true};
                }
                resolve();
            });
            // 继续向下执行
            await next();
        };
    },
    pushLog(msg){
      if(logData.leng>100){
          logData.splice(0,50);
      }
      logData.push(manba().format("f")+"----"+msg);
    },
    getLog(){
         return logData;
    },
    clearLog(){
        logData=null;
        logData=[];
    }
    
   
}